// 支持使用返回一个函数来定制表单
export default function (sdk) {
  return {
    'form-id3': async (context) => {
      const res = await sdk.http.get('/example-api/accounts')
      const accounts = res.data

      if (accounts.length) {
        sdk.message(`成功获取到 ${accounts.length} 条账户记录.`)
      } else {
        sdk.message.error('获取失败')
      }

      context.$on('button.click', ({ button }) => {
        if (button.id === 'button-id') {
          const id = sdk.utils.id.create()

          context.form.dataService.data['data-id-1'] = id
          context.form.dataService.data['data-id-2'] = accounts.length
        }

        sdk.router.go(-1)
      })
    }
  }
}
